package mymac.com.test_3_1;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.ViewConfiguration;
import android.widget.FrameLayout;
import android.widget.RadioGroup;

import java.lang.reflect.Field;

public class MainActivity extends AppCompatActivity {

    private FrameLayout fl_content;
    static RadioGroup rg_content;
    private Activity activity;
    private FragmentManager fm;
    private FragmentTransaction ft;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fl_content = (FrameLayout) findViewById(R.id.fl_content);
        rg_content = (RadioGroup) findViewById(R.id.rg_content);
        rg_content.check(R.id.rb_deps);
        activity = this;

        rg_content.setOnCheckedChangeListener(new MyOnCheckedChangeListener());

        fm = getFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.fl_content,new DepsFragment());
        ft.commit();

    }

    class MyOnCheckedChangeListener implements RadioGroup.OnCheckedChangeListener{
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            ft = fm.beginTransaction();
            switch (i){
                case R.id.rb_deps:
                    ft.replace(R.id.fl_content,new DepsFragment());
                    break;
                case R.id.rb_data:
                    ft.replace(R.id.fl_content,new DataFragment());
                    break;
                case R.id.rb_project:
                    ft.replace(R.id.fl_content,new ProjectFragment());
                    break;
                case R.id.rb_home:
                    ft.replace(R.id.fl_content,new MyHomeFragment());
                    break;
            }
            ft.commit();
        }
    }
}